import pygame
from pygame.locals import *
from Widget import *

class VScroll(Widget):
   """ Simple scroll widget. """
   def __init__(self, rect):
      Widget.__init__(self)
      self.up = pygame.image.load('scroll_up_but.png')
      self.down = pygame.image.load('scroll_down_but.png')
      self.marker = pygame.image.load('scroll_counter.png')
      self.rect = pygame.Rect(rect[0], rect[1], rect[2], rect[3])
      self.pos = self.up.get_height()
      self.can_drag = True

   def draw(self):
      pygame.draw.rect(self.screen, (32,32,32), (self.get_x(), self.get_y(), self.rect.w, self.rect.h))
      self.screen.blit(self.up, (self.get_x(), self.get_y(), self.rect.w, self.up.get_height()))
      self.screen.blit(self.down,
         (  self.get_x(), 
            self.get_y()+self.rect.h-self.down.get_height(), 
            self.rect.w, 
            self.down.get_height()))
      self.screen.blit(self.marker, 
         (  self.get_x(), 
            self.get_y() + self.pos, 
            self.rect.w, 
            self.marker.get_height()))

   def move(self, loc):
      self.pos += loc[1]
      #if self.pos + loc[1] > self.up.get_height() and self.pos + loc[1] < self.rect.height - self.down.get_height() - self.marker.get_height():
      #   self.pos += loc[1]